use "Data\Wave 7.dta", clear

***** Add in socio-demogaphic information from previous waves
merge 1:1 v_ID using "Data\Wave 1.dta", ///
keepusing(w1_occ w1_citizen_1)
drop if _merge == 2
drop _merge

merge 1:1 v_ID using "Data\Wave 2.dta", ///
keepusing(w2_occ w2_citizen_1)
drop if _merge == 2
drop _merge

merge 1:1 v_ID using "Data\Wave 3.dta", ///
keepusing(w3_occ w3_citizenr1)
drop if _merge == 2
drop _merge

merge 1:1 v_ID using "Data\Wave 4.dta", ///
keepusing(w4_occ w4_citizenr1)
drop if _merge == 2
drop _merge

merge 1:1 v_ID using "Data\Wave 5.dta", ///
keepusing(w5_occ w5_citizenr1)
drop if _merge == 2
drop _merge

merge 1:1 v_ID using "Data\Wave 6", ///
keepusing(w6_occ w6_citizenr1)
drop if _merge == 2
drop _merge

generate ukcitizen = w1_citizen_1
replace ukcitizen = w2_citizen_1 if ukcitizen== .
replace ukcitizen = w3_citizenr1 if ukcitizen== .
replace ukcitizen = w4_citizenr1 if ukcitizen== .
replace ukcitizen = w5_citizenr1 if ukcitizen== .
replace ukcitizen = w6_citizenr1 if ukcitizen== .
replace ukcitizen = w7_citizenr1 if ukcitizen== .

generate occup = w1_occ
replace occup = w2_occ if occup == .
replace occup = w3_occ if occup == .
replace occup = w4_occ if occup == .
replace occup = w5_occ if occup == .
replace occup = w6_occ if occup == .
replace occup = w7_occ if occup == .
label values occup w7_occ

recode occup (1=1) (2=2) (3=1) (4=2) (5/6=3) (7=2) (8=1) (9/10=4), generate (occup4)
label define occup4 1 "Professional and senior management" ///
2 "Intermediate occupations" 3 "Semi-routine and routine" ///
4 "Other or never worked"
label values  occup4 occup4

recode occup4 (1=4) (2=3) (3=2) (4=1), generate (occup4rev)
label define occup4rev 4 "Professional and senior management" ///
3 "Intermediate occupations" 2 "Semi-routine and routine" ///
1 "Other or never worked"
label values  occup4rev occup4rev

recode occup (1/3=0) (4=1) (5/6=1) (7/10=0), gen (wc)
recode occup (1=1) (2=0) (3=1) (4/7=0) (8=1) (9/10=0), gen (mc)

rename age_derived age
rename gender_derived sex
rename religion_derived religion

recode sex (1=0) (2=1), generate (female)
recode ethnicity (1=1) (2/18=0), generate (whitebrit)

recode region (1/9=1) (10/12=0), gen (england)
recode region (1/9=1) (10=2) (11=3) (12=4), gen (region4)
 label define region4 1 " England" 2 "Wales" 3 "Scotland" ///
 4 "Northern Ireland"
 label values region4 region4
recode region (1/5=1) (6/9=2) (10=3) (11=4) (12=5), gen (region5)
 label define region5 1 " Northerners" 2 "Southerners" 3 "Wales" ///
 4 "Scotland" 5 "Northern Ireland"
 label values region5 region5
 
gen northerners = .
replace northerners = 1 if region < 4 

gen southerners = .
replace southerners = 1 if region == 8
replace southerners = 1 if region == 9

gen northerners2 = northerners
replace northerners2 = 0 if northerners == .

drop w1_occ w1_citizen_1 w2_occ w2_citizen_1 w3_occ w3_citizenr1 w4_occ w4_citizenr1 ///
w5_occ w5_citizenr1 w6_occ w6_citizenr1

*** Identities ****
rename w7_natidr1 british
rename w7_natidr2 english
rename w7_natidr3 european
rename w7_natidr4 irish
rename w7_natidr5 nirish
rename w7_natidr6 scottish
rename w7_natidr7 ulster
rename w7_natidr8 welsh
rename w7_natidr9 other

egen byte count_natid = anycount(british english european irish nirish scottish ulster welsh other), values(1)
tab count_natid

generate natid = . 
replace natid = 1 if english == 1 & count_natid == 1
replace natid = 2 if british == 1 & count_natid == 1
replace natid = 3 if british == 1 & english == 1 & count_natid == 2
replace natid = 4 if british == 1 & natid == .
replace natid = 5 if welsh == 1 & natid == .
replace natid = 5 if scottish == 1 & natid == .
replace natid = 5 if irish == 1 & natid == .
replace natid = 5 if nirish == 1 & natid == .
replace natid = 5 if ulster == 1 & natid == .

label def natid1 1 "English only" ///
2 "British only" ///
3 "British and English" ///
4 "Other British mixed" ///
5 "Other UK ids" 

generate natid2 = . 
replace natid2 = 1 if english == 1 & count_natid == 1
replace natid2 = 2 if welsh == 1 & count_natid == 1
replace natid2 = 4 if scottish == 1 & count_natid == 1
replace natid2 = 5 if european == 1 & count_natid == 1
replace natid2 = 6 if irish == 1 & count_natid == 1
replace natid2 = 6 if nirish == 1 & count_natid == 1
replace natid2 = 3 if british == 1 & count_natid == 1
replace natid2 = 7 if british == 1 & natid2 == .

label def natid2 1 "English only" ///
2 "Welsh only" 3 "British only" ///
4 "Scottish only" 5 "European only" ///
6 "Irish/ N Irish only" 7 "British dual/ mixed"
label values natid2 natid2

recode natid2 (2=.) (4/6=.), generate (engbrit2)
label values engbrit2 natid2

recode natid2 (1/2=0) (3=1) (4/7=0), gen (brit_only)

**** Authoritarianism and L/R factors ****
recode w7_authoritarianr1 (6=.), generate (authoritarian_youngrespect)
label values authoritarian_youngrespect w7_authoritarianr1
recode w7_authoritarianr2 (6=.), generate (authoritarian_deathpen)
label values authoritarian_deathpen w7_authoritarianr2
recode w7_authoritarianr3 (6=.), generate (authoritarian_obey)
label values authoritarian_obey w7_authoritarianr3
recode w7_authoritarianr4 (6=.), generate (authoritarian_censorship)
label values authoritarian_censorship w7_authoritarianr4
recode w7_authoritarianr5 (6=.), generate (authoritarian_stiffsentences)
label values authoritarian_stiffsentences w7_authoritarianr5

recode w7_authoritarianr6 (6=.), generate (leftright_redistribute)
label values leftright_redistribute w7_authoritarianr6
recode w7_authoritarianr7 (6=.), generate (leftright_bigbusiness)
label values leftright_bigbusiness w7_authoritarianr7
recode w7_authoritarianr8 (6=.), generate (leftright_sharewealth)
label values leftright_sharewealth w7_authoritarianr8
recode w7_authoritarianr9 (6=.), generate (leftright_law)
label values leftright_law w7_authoritarianr9
recode w7_authoritarianr10 (6=.), generate (leftright_management)
label values leftright_management w7_authoritarianr10

factor authoritarian_youngrespect authoritarian_deathpen ///
authoritarian_obey authoritarian_censorship ///
authoritarian_stiffsentences, factors(1)
  predict auth_factor, regression
  replace auth_factor = auth_factor *-1
  
factor  leftright_redistribute leftright_bigbusiness ///
 leftright_sharewealth leftright_law ///
 leftright_management, factors(1)
  predict right_factor, regression


****************************
** Education ***
recode wt_edu (1/3=1) (4=2) (5=3) (6=4) (7/8=5), generate (quals5)
label define quals5 1 "Degree or higher" 2 "Other higher ed" ///
3 "A level etc" 4 "GCSE etc" 5 "Other/ none"
label values quals5 quals5

recode quals5 (1=5) (2=4) (3=3) (4=2) (5=1), gen (quals5rev)

recode wt_edu (1=1) (2/3=2) (4=3) (5=4) (6=5) (7/8=6), generate (quals6)
label define quals6 1 "Higher degree" 2 "Degree" 3 "Other higher ed" ///
4 "A level etc" 5 "GCSE etc" 6 "Other/ none"
label values quals6 quals6

**** Stereotypes ****

recode W7_stereo_A_1r1 - W7_stereo_C_6r5 (-99=.)
recode W7_stereo_A_1r1 - W7_stereo_C_6r5 (4=3)

************
***** Stereotyping items ***
** RECODING ***
recode  W7_stereo_A_1r1 (1=1) (2=0) (3=.), gen (hardwork_mc)
recode  W7_stereo_A_1r2 (1=1) (2=0) (3=.), gen (geton_mc) 
recode  W7_stereo_A_1r3 (1=1) (2=0) (3=.), gen (straight_mc) 
recode  W7_stereo_A_1r4 (1=1) (2=0) (3=.), gen (friendly_mc) 
recode  W7_stereo_A_1r5 (1=1) (2=0) (3=.), gen (values_mc) 
 *

*** Working class
	 recode  W7_stereo_A_2r1 (1=1) (2=0) (3=.), gen (hardwork_wc)
 recode  W7_stereo_A_2r2 (1=1) (2=0) (3=.), gen (geton_wc) 
  recode  W7_stereo_A_2r3 (1=1) (2=0) (3=.), gen (straight_wc) 
recode  W7_stereo_A_2r4 (1=1) (2=0) (3=.), gen (friendly_wc) 
recode  W7_stereo_A_2r5 (1=1) (2=0) (3=.), gen (values_wc) 
	
*** 	Scots
recode  W7_stereo_A_3r1 (1=1) (2=0) (3=.), gen (hardwork_scot)
recode  W7_stereo_A_3r2 (1=1) (2=0) (3=.), gen (geton_scot) 
recode  W7_stereo_A_3r3 (1=1) (2=0) (3=.), gen (straight_scot) 
recode  W7_stereo_A_3r4 (1=1) (2=0) (3=.), gen (friendly_scot) 
recode  W7_stereo_A_3r5 (1=1) (2=0) (3=.), gen (values_scot) 

*** 	English
recode  W7_stereo_A_4r1 (1=1) (2=0) (3=.), gen (hardwork_eng)
recode  W7_stereo_A_4r2 (1=1) (2=0) (3=.), gen (geton_eng) 
recode  W7_stereo_A_4r3 (1=1) (2=0) (3=.), gen (straight_eng) 
recode  W7_stereo_A_4r4 (1=1) (2=0) (3=.), gen (friendly_eng) 
recode  W7_stereo_A_4r5 (1=1) (2=0) (3=.), gen (values_eng) 

*** 	Black Caribbean
recode  W7_stereo_A_5r1 (1=1) (2=0) (3=.), gen (hardwork_bc)
recode  W7_stereo_A_5r2 (1=1) (2=0) (3=.), gen (geton_bc) 
recode  W7_stereo_A_5r3 (1=1) (2=0) (3=.), gen (straight_bc) 
recode  W7_stereo_A_5r4 (1=1) (2=0) (3=.), gen (friendly_bc) 
recode  W7_stereo_A_5r5 (1=1) (2=0) (3=.), gen (values_bc) 
	
*** 	White British
recode  W7_stereo_A_6r1 (1=1) (2=0) (3=.), gen (hardwork_awb)
recode  W7_stereo_A_6r2 (1=1) (2=0) (3=.), gen (geton_awb) 
recode  W7_stereo_A_6r3 (1=1) (2=0) (3=.), gen (straight_awb) 
recode  W7_stereo_A_6r4 (1=1) (2=0) (3=.), gen (friendly_awb) 
recode  W7_stereo_A_6r5 (1=1) (2=0) (3=.), gen (values_awb) 

	
*** 	Northerners
recode  W7_stereo_B_1r1 (1=1) (2=0) (3=.), gen (hardwork_north)
recode  W7_stereo_B_1r2 (1=1) (2=0) (3=.), gen (geton_north) 
recode  W7_stereo_B_1r3 (1=1) (2=0) (3=.), gen (straight_north) 
recode  W7_stereo_B_1r4 (1=1) (2=0) (3=.), gen (friendly_north) 
recode  W7_stereo_B_1r5 (1=1) (2=0) (3=.), gen (values_north) 

	
*** 	Southerners
recode  W7_stereo_B_2r1 (1=1) (2=0) (3=.), gen (hardwork_south)
recode  W7_stereo_B_2r2 (1=1) (2=0) (3=.), gen (geton_south) 
recode  W7_stereo_B_2r3 (1=1) (2=0) (3=.), gen (straight_south) 
recode  W7_stereo_B_2r4 (1=1) (2=0) (3=.), gen (friendly_south) 
recode  W7_stereo_B_2r5 (1=1) (2=0) (3=.), gen (values_south) 

	
*** 	Irish
recode  W7_stereo_B_3r1 (1=1) (2=0) (3=.), gen (hardwork_irish)
recode  W7_stereo_B_3r2 (1=1) (2=0) (3=.), gen (geton_irish) 
recode  W7_stereo_B_3r3 (1=1) (2=0) (3=.), gen (straight_irish) 
recode  W7_stereo_B_3r4 (1=1) (2=0) (3=.), gen (friendly_irish) 
recode  W7_stereo_B_3r5 (1=1) (2=0) (3=.), gen (values_irish) 


*** 	English
recode  W7_stereo_B_4r1 (1=1) (2=0) (3=.), gen (hardwork_beng)
recode  W7_stereo_B_4r2 (1=1) (2=0) (3=.), gen (geton_beng) 
recode  W7_stereo_B_4r3 (1=1) (2=0) (3=.), gen (straight_beng) 
recode  W7_stereo_B_4r4 (1=1) (2=0) (3=.), gen (friendly_beng) 
recode  W7_stereo_B_4r5 (1=1) (2=0) (3=.), gen (values_beng) 


*** 	Pakistani
recode  W7_stereo_B_5r1 (1=1) (2=0) (3=.), gen (hardwork_pak)
recode  W7_stereo_B_5r2 (1=1) (2=0) (3=.), gen (geton_pak) 
recode  W7_stereo_B_5r3 (1=1) (2=0) (3=.), gen (straight_pak) 
recode  W7_stereo_B_5r4 (1=1) (2=0) (3=.), gen (friendly_pak) 
recode  W7_stereo_B_5r5 (1=1) (2=0) (3=.), gen (values_pak) 

	
*** 	White British
recode  W7_stereo_B_6r1 (1=1) (2=0) (3=.), gen (hardwork_bwb)
recode  W7_stereo_B_6r2 (1=1) (2=0) (3=.), gen (geton_bwb) 
recode  W7_stereo_B_6r3 (1=1) (2=0) (3=.), gen (straight_bwb) 
recode  W7_stereo_B_6r4 (1=1) (2=0) (3=.), gen (friendly_bwb) 
recode  W7_stereo_B_6r5 (1=1) (2=0) (3=.), gen (values_bwb) 


*** 	Welsh
recode  W7_stereo_C_1r1 (1=1) (2=0) (3=.), gen (hardwork_wel)
recode  W7_stereo_C_1r2 (1=1) (2=0) (3=.), gen (geton_wel) 
recode  W7_stereo_C_1r3 (1=1) (2=0) (3=.), gen (straight_wel) 
recode  W7_stereo_C_1r4 (1=1) (2=0) (3=.), gen (friendly_wel) 
recode  W7_stereo_C_1r5 (1=1) (2=0) (3=.), gen (values_wel) 

	
*** 	English
recode  W7_stereo_C_2r1 (1=1) (2=0) (3=.), gen (hardwork_ceng)
recode  W7_stereo_C_2r2 (1=1) (2=0) (3=.), gen (geton_ceng) 
recode  W7_stereo_C_2r3 (1=1) (2=0) (3=.), gen (straight_ceng) 
recode  W7_stereo_C_2r4 (1=1) (2=0) (3=.), gen (friendly_ceng) 
recode  W7_stereo_C_2r5 (1=1) (2=0) (3=.), gen (values_ceng) 


*** 	White British
recode  W7_stereo_C_3r1 (1=1) (2=0) (3=.), gen (hardwork_cwb)
recode  W7_stereo_C_3r2 (1=1) (2=0) (3=.), gen (geton_cwb) 
recode  W7_stereo_C_3r3 (1=1) (2=0) (3=.), gen (straight_cwb) 
recode  W7_stereo_C_3r4 (1=1) (2=0) (3=.), gen (friendly_cwb) 
recode  W7_stereo_C_3r5 (1=1) (2=0) (3=.), gen (values_cwb) 


*** 	Indian background
recode  W7_stereo_C_4r1 (1=1) (2=0) (3=.), gen (hardwork_ind)
recode  W7_stereo_C_4r2 (1=1) (2=0) (3=.), gen (geton_ind) 
recode  W7_stereo_C_4r3 (1=1) (2=0) (3=.), gen (straight_ind) 
recode  W7_stereo_C_4r4 (1=1) (2=0) (3=.), gen (friendly_ind) 
recode  W7_stereo_C_4r5 (1=1) (2=0) (3=.), gen (values_ind) 

	
*** 	Polish
recode  W7_stereo_C_5r1 (1=1) (2=0) (3=.), gen (hardwork_pol)
recode  W7_stereo_C_5r2 (1=1) (2=0) (3=.), gen (geton_pol) 
recode  W7_stereo_C_5r3 (1=1) (2=0) (3=.), gen (straight_pol) 
recode  W7_stereo_C_5r4 (1=1) (2=0) (3=.), gen (friendly_pol) 
recode  W7_stereo_C_5r5 (1=1) (2=0) (3=.), gen (values_pol) 


*** 	Roma/ Gypsy
recode  W7_stereo_C_6r1 (1=1) (2=0) (3=.), gen (hardwork_rom)
recode  W7_stereo_C_6r2 (1=1) (2=0) (3=.), gen (geton_rom) 
recode  W7_stereo_C_6r3 (1=1) (2=0) (3=.), gen (straight_rom) 
recode  W7_stereo_C_6r4 (1=1) (2=0) (3=.), gen (friendly_rom) 
recode  W7_stereo_C_6r5 (1=1) (2=0) (3=.), gen (values_rom) 

************************
************************
** CLOSE TO REGION/ COUNTRY
** Recoding and descriptives ***
table w7_locr1  [pweight = finalweight]	
table w7_locr2  [pweight = finalweight]	
table w7_locr3  [pweight = finalweight]	
table w7_locr4  [pweight = finalweight]	

recode w7_locr1 (1/2=1) (3/4=0), gen (closetolocal)
replace closetolocal = closetolocal *100
recode w7_locr2 (1/2=1) (3/4=0), gen (closetoregion)
replace closetoregion = closetoregion *100
recode w7_locr3 (1/2=1) (3/4=0), gen (closetoUK)
replace closetoUK = closetoUK *100
recode w7_locr4 (1/2=1) (3/4=0), gen (closetoEurope)
replace closetoEurope = closetoEurope *100

	******************


*** Making the tables for DIVIDED BRITAIN Paper ***
***** TABLE1 *****
mean values_awb [pweight = finalweight]	 if brit_only == 1 & ukcitizen == 1	 
mean geton_awb [pweight = finalweight] if brit_only == 1 & ukcitizen == 1
mean straight_awb [pweight = finalweight]  if brit_only == 1 & ukcitizen == 1
*
mean values_bwb [pweight = finalweight]	 if brit_only == 1 & ukcitizen == 1
mean geton_bwb [pweight = finalweight]  if brit_only == 1 & ukcitizen == 1
mean straight_bwb [pweight = finalweight]   if brit_only == 1 & ukcitizen == 1
*
mean values_cwb [pweight = finalweight]	 if brit_only == 1 & ukcitizen == 1
mean geton_cwb [pweight = finalweight] if brit_only == 1 & ukcitizen == 1
mean straight_cwb [pweight = finalweight]  if brit_only == 1 & ukcitizen == 1
******** take average of a/b/c for british estimate.
***** English (Group A)
mean values_eng [pweight = finalweight]	 if brit_only == 1 & ukcitizen == 1
mean geton_eng [pweight = finalweight] if brit_only == 1 & ukcitizen == 1
mean straight_eng [pweight = finalweight]  if brit_only == 1 & ukcitizen == 1

mean values_beng [pweight = finalweight]	 if brit_only == 1 & ukcitizen == 1
mean geton_beng [pweight = finalweight] if brit_only == 1 & ukcitizen == 1
mean straight_beng [pweight = finalweight]  if brit_only == 1 & ukcitizen == 1

mean values_ceng [pweight = finalweight]	 if brit_only == 1 & ukcitizen == 1
mean geton_ceng [pweight = finalweight] if brit_only == 1 & ukcitizen == 1
mean straight_ceng [pweight = finalweight]  if brit_only == 1 & ukcitizen == 1
******* take average of a/b/c for english estimate.
**** Welsh (Group C)
mean values_wel [pweight = finalweight]	 if brit_only == 1 & ukcitizen == 1
mean geton_wel [pweight = finalweight] if brit_only == 1 & ukcitizen == 1
mean straight_wel [pweight = finalweight]  if brit_only == 1 & ukcitizen == 1
****
**** Irish (Group B)
mean values_irish [pweight = finalweight]	 if brit_only == 1 & ukcitizen == 1
mean geton_irish [pweight = finalweight] if brit_only == 1 & ukcitizen == 1
mean straight_irish [pweight = finalweight]  if brit_only == 1 & ukcitizen == 1
****
**** Scottish (Group A)
mean values_scot [pweight = finalweight]	 if brit_only == 1 & ukcitizen == 1
mean geton_scot [pweight = finalweight] if brit_only == 1 & ukcitizen == 1
mean straight_scot [pweight = finalweight]  if brit_only == 1 & ukcitizen == 1

** SIGNIFICANCE TESTS
* 1) WB vs English
ttest values_awb == values_eng if brit_only == 1 & ukcitizen == 1
ttest geton_awb == geton_eng if brit_only == 1 & ukcitizen == 1
ttest straight_awb == straight_eng if brit_only == 1 & ukcitizen == 1
* 2) WB vs Welsh
ttest values_cwb == values_wel if brit_only == 1 & ukcitizen == 1
ttest geton_cwb == geton_wel if brit_only == 1 & ukcitizen == 1
ttest straight_cwb == straight_wel if brit_only == 1 & ukcitizen == 1
* 3) WB vs Irish 
ttest values_bwb == values_irish if brit_only == 1 & ukcitizen == 1
ttest geton_bwb == geton_irish if brit_only == 1 & ukcitizen == 1
ttest straight_bwb == straight_irish if brit_only == 1 & ukcitizen == 1
* 4) WB vs Scottish
ttest values_awb == values_scot if brit_only == 1 & ukcitizen == 1
ttest geton_awb == geton_scot if brit_only == 1 & ukcitizen == 1
ttest straight_awb == straight_scot if brit_only == 1 & ukcitizen == 1
*********************
*********************

***** TABLE 2A
mean values_eng [pweight = finalweight]	 if english == 1 & ukcitizen == 1
mean geton_eng [pweight = finalweight] if english == 1 & ukcitizen == 1
mean straight_eng [pweight = finalweight]  if english == 1 & ukcitizen == 1

mean values_beng [pweight = finalweight] if english == 1 & ukcitizen == 1
mean geton_beng [pweight = finalweight] if english == 1 & ukcitizen == 1
mean straight_beng [pweight = finalweight] if english == 1 & ukcitizen == 1

mean values_ceng [pweight = finalweight] if english == 1 & ukcitizen == 1
mean geton_ceng [pweight = finalweight] if english == 1 & ukcitizen == 1
mean straight_ceng [pweight = finalweight] if english == 1 & ukcitizen == 1
*** take average of a/b/c for english estimate.
***
mean values_eng [pweight = finalweight]	 if scottish == 1 
mean geton_eng [pweight = finalweight] if scottish == 1 
mean straight_eng [pweight = finalweight]  if scottish == 1 
**
mean values_scot [pweight = finalweight] if english == 1 
mean geton_scot [pweight = finalweight] if english == 1 
mean straight_scot [pweight = finalweight] if english == 1 
*
mean values_scot [pweight = finalweight] if scottish == 1 
mean geton_scot [pweight = finalweight] if scottish == 1 
mean straight_scot [pweight = finalweight] if scottish == 1 

******
ttest values_eng == values_scot if english == 1 
ttest geton_eng == geton_scot if english == 1 
ttest straight_eng == straight_scot if english == 1 
*
ttest values_eng == values_scot if scottish == 1 
ttest geton_eng == geton_scot if scottish == 1 
ttest straight_eng == straight_scot if scottish == 1 

***** TABLE 2B
mean values_eng [pweight = finalweight]	 if english == 1 & ukcitizen == 1
mean geton_eng [pweight = finalweight] if english == 1 & ukcitizen == 1
mean straight_eng [pweight = finalweight]  if english == 1 & ukcitizen == 1

mean values_beng [pweight = finalweight]	 if english == 1 & ukcitizen == 1
mean geton_beng [pweight = finalweight] if english == 1 & ukcitizen == 1
mean straight_beng [pweight = finalweight]  if english == 1 & ukcitizen == 1

mean values_ceng [pweight = finalweight]	 if english == 1 & ukcitizen == 1
mean geton_ceng [pweight = finalweight] if english == 1 & ukcitizen == 1
mean straight_ceng [pweight = finalweight]  if english == 1 & ukcitizen == 1
* *** take average of a/b/c for english estimate.

mean values_wel [pweight = finalweight]	if english == 1 & ukcitizen == 1 
mean geton_wel [pweight = finalweight] if english == 1 & ukcitizen == 1 
mean straight_wel [pweight = finalweight] if english == 1 & ukcitizen == 1 
**** 
****
mean values_wel [pweight = finalweight]	 if welsh == 1 & ukcitizen == 1
mean geton_wel [pweight = finalweight] if welsh == 1 & ukcitizen == 1
mean straight_wel [pweight = finalweight]  if welsh == 1 & ukcitizen == 1
*
mean values_ceng [pweight = finalweight] if welsh == 1 & ukcitizen == 1
mean geton_ceng [pweight = finalweight] if welsh == 1 & ukcitizen == 1
mean straight_ceng [pweight = finalweight]  if welsh == 1 & ukcitizen == 1
******
ttest values_ceng == values_wel if english == 1 & ukcitizen == 1
ttest geton_ceng == geton_wel if english == 1 & ukcitizen == 1
ttest straight_ceng == straight_wel if english == 1 & ukcitizen == 1
*
ttest values_ceng == values_wel if welsh == 1 & ukcitizen == 1
ttest geton_ceng == geton_wel if welsh == 1 & ukcitizen == 1
ttest straight_ceng == straight_wel if welsh == 1 & ukcitizen == 1
**
**
****
* TABLE 3 *
mean values_wc [pweight = finalweight]	if wc == 1 & ukcitizen == 1 & england == 1
mean geton_wc [pweight = finalweight] if wc == 1 & ukcitizen == 1 & england == 1
mean straight_wc [pweight = finalweight]  if wc == 1 & ukcitizen == 1 & england == 1
*
mean values_mc [pweight = finalweight]	if wc == 1 & ukcitizen == 1 & england == 1
mean geton_mc [pweight = finalweight] if wc == 1 & ukcitizen == 1 & england == 1
mean straight_mc [pweight = finalweight]  if wc == 1 & ukcitizen == 1 & england == 1
*
mean values_wc [pweight = finalweight]	if mc == 1 & ukcitizen == 1 & england == 1
mean geton_wc [pweight = finalweight] if mc == 1 & ukcitizen == 1 & england == 1
mean straight_wc [pweight = finalweight]  if mc == 1 & ukcitizen == 1 & england == 1
*
mean values_mc [pweight = finalweight]	if mc == 1 & ukcitizen == 1 & england == 1
mean geton_mc [pweight = finalweight] if mc == 1 & ukcitizen == 1 & england == 1
mean straight_mc [pweight = finalweight]  if mc == 1 & ukcitizen == 1 & england == 1

*** T-tests ***
ttest values_wc == values_mc if wc == 1 & ukcitizen == 1 & england == 1
ttest geton_wc == geton_mc if wc == 1 & ukcitizen == 1 & england == 1
ttest straight_wc == straight_mc if wc == 1 & ukcitizen == 1 & england == 1
*
ttest values_wc == values_mc if mc == 1 & ukcitizen == 1 & england == 1
ttest geton_wc == geton_mc if mc == 1 & ukcitizen == 1 & england == 1
ttest straight_wc == straight_mc if mc == 1 & ukcitizen == 1 & england == 1

***** TABLE 4
mean values_north [pweight = finalweight] if northerners == 1 & closetoregion == 100 & ukcitizen == 1
mean geton_north [pweight = finalweight] if northerners == 1 & closetoregion == 100 & ukcitizen == 1
mean straight_north [pweight = finalweight] if northerners == 1 & closetoregion == 100 & ukcitizen == 1
*	
mean values_south [pweight = finalweight] if northerners == 1 & closetoregion == 100 & ukcitizen == 1
mean geton_south [pweight = finalweight] if northerners == 1 & closetoregion == 100 & ukcitizen == 1
mean straight_south [pweight = finalweight] if northerners == 1 & closetoregion == 100 & ukcitizen == 1
*****
mean values_north [pweight = finalweight] if southerners == 1 & closetoregion == 100 & ukcitizen == 1
mean geton_north [pweight = finalweight] if southerners == 1 & closetoregion == 100 & ukcitizen == 1
mean straight_north [pweight = finalweight] if southerners == 1 & closetoregion == 100 & ukcitizen == 1
*
mean values_south [pweight = finalweight] if southerners == 1 & closetoregion == 100 & ukcitizen == 1
mean geton_south [pweight = finalweight] if southerners == 1 & closetoregion == 100 & ukcitizen == 1
mean straight_south [pweight = finalweight] if southerners == 1 & closetoregion == 100 & ukcitizen == 1
**** SIGNIFICANCE TESTING
* 
ttest values_north == values_south if northerners == 1  & closetoregion == 100 & ukcitizen == 1
ttest geton_north == geton_south if northerners == 1  & closetoregion == 100 & ukcitizen == 1 
ttest straight_north == straight_south if northerners == 1  & closetoregion == 100 & ukcitizen == 1
**
ttest values_north == values_south if southerners == 1& closetoregion == 100 & ukcitizen == 1
ttest geton_north == geton_south if southerners == 1 & closetoregion == 100 & ukcitizen == 1
ttest straight_north == straight_south if southerners == 1 & closetoregion == 100 & ukcitizen == 1


**** APPENDIX *****
** Table A2
mean geton_awb [pweight = finalweight] if ethnicity == 1 & ukcitizen == 1
mean straight_awb [pweight = finalweight]  if ethnicity == 1 & ukcitizen == 1
mean values_awb [pweight = finalweight]	 if ethnicity == 1	& ukcitizen == 1 
*
mean geton_bwb [pweight = finalweight]  if ethnicity == 1 & ukcitizen == 1
mean straight_bwb [pweight = finalweight]   if ethnicity == 1 & ukcitizen == 1
mean values_bwb [pweight = finalweight]	 if ethnicity == 1 & ukcitizen == 1
*
mean geton_cwb [pweight = finalweight] if ethnicity == 1 & ukcitizen == 1
mean straight_cwb [pweight = finalweight]  if ethnicity == 1 & ukcitizen == 1
mean values_cwb [pweight = finalweight]	 if ethnicity == 1 & ukcitizen == 1
***** *** take average of a/b/c for white british estimate.
****
** Polish group C
mean geton_pol [pweight = finalweight] if ethnicity == 1  & ukcitizen == 1
mean straight_pol [pweight = finalweight] if ethnicity == 1 & ukcitizen == 1
mean values_pol [pweight = finalweight]	 if ethnicity == 1 & ukcitizen == 1
****
** Black Caribbean Group A
mean geton_bc [pweight = finalweight] if ethnicity == 1 & ukcitizen == 1
mean straight_bc [pweight = finalweight]  if ethnicity == 1 & ukcitizen == 1
mean values_bc [pweight = finalweight]	 if ethnicity == 1 & ukcitizen == 1
****
** Indian Group C
mean geton_ind [pweight = finalweight] if ethnicity == 1 & ukcitizen == 1
mean straight_ind [pweight = finalweight] if ethnicity == 1 & ukcitizen == 1
mean values_ind [pweight = finalweight]	if ethnicity == 1 & ukcitizen == 1
***
** Pakistani Group B
mean geton_pak [pweight = finalweight] if ethnicity == 1 & ukcitizen == 1
mean straight_pak [pweight = finalweight]  if ethnicity == 1 & ukcitizen == 1
mean values_pak [pweight = finalweight]	 if ethnicity == 1 & ukcitizen == 1
****
*** Roma Group C
mean geton_rom [pweight = finalweight] if ethnicity == 1 & ukcitizen == 1
mean straight_rom [pweight = finalweight]  if ethnicity == 1 & ukcitizen == 1
mean values_rom [pweight = finalweight]		 if ethnicity == 1 & ukcitizen == 1
*****
* Note that Table A2 also uses data from the European Social Survey 2016.
*****
** SIGNIFICANCE TESTS
** NB using paired T-test
* 1) WB vs Polish 
ttest values_cwb == values_pol if ethnicity == 1 & ukcitizen == 1
ttest geton_cwb == geton_pol if ethnicity == 1 & ukcitizen == 1
ttest straight_cwb == straight_pol if ethnicity == 1 & ukcitizen == 1
* 2) WB vs Black Caribbean 
ttest values_awb == values_bc if ethnicity == 1 & ukcitizen == 1
ttest geton_awb == geton_bc if ethnicity == 1 & ukcitizen == 1
ttest straight_awb == straight_bc if ethnicity == 1 & ukcitizen == 1
* 3) WB vs Indian
ttest values_cwb == values_ind if ethnicity == 1 & ukcitizen == 1
ttest geton_cwb == geton_ind if ethnicity == 1 & ukcitizen == 1
ttest straight_cwb == straight_ind if ethnicity == 1 & ukcitizen == 1
* 4) WB vs Pakistani
ttest values_bwb == values_pak if ethnicity == 1 & ukcitizen == 1
ttest geton_bwb == geton_pak if ethnicity == 1 & ukcitizen == 1
ttest straight_bwb == straight_pak if ethnicity == 1 & ukcitizen == 1
* 5) WB vs Roma
ttest values_cwb == values_rom if ethnicity == 1 & ukcitizen == 1
ttest geton_cwb == geton_rom if ethnicity == 1 & ukcitizen == 1
ttest straight_cwb == straight_rom if ethnicity == 1 & ukcitizen == 1
**
***** TABLE A4
mean values_north [pweight = finalweight] if region5 == 1 & closetoregion == 100 & ukcitizen == 1
mean geton_north [pweight = finalweight] if region5 == 1 & closetoregion == 100 & ukcitizen == 1
mean straight_north [pweight = finalweight] if region5 == 1 & closetoregion == 100 & ukcitizen == 1
*	
mean values_south [pweight = finalweight] if region5 == 1 & closetoregion == 100 & ukcitizen == 1
mean geton_south [pweight = finalweight] if region5 == 1 & closetoregion == 100 & ukcitizen == 1
mean straight_south [pweight = finalweight] if region5 == 1 & closetoregion == 100 & ukcitizen == 1
*****
mean values_north [pweight = finalweight] if region5 == 2 & closetoregion == 100 & ukcitizen == 1
mean geton_north [pweight = finalweight] if region5 == 2 & closetoregion == 100 & ukcitizen == 1
mean straight_north [pweight = finalweight] if region5 == 2 & closetoregion == 100 & ukcitizen == 1
*
mean values_south [pweight = finalweight] if region5 == 2 & closetoregion == 100 & ukcitizen == 1
mean geton_south [pweight = finalweight] if region5 == 2 & closetoregion == 100 & ukcitizen == 1
mean straight_south [pweight = finalweight] if region5 == 2 & closetoregion == 100 & ukcitizen == 1
**** SIGNIFICANCE TESTING
* 
ttest values_north == values_south if region5 == 1 & closetoregion == 100 & ukcitizen == 1
ttest geton_north == geton_south if region5 == 1 & closetoregion == 100 & ukcitizen == 1 
ttest straight_north == straight_south if region5 == 1 & closetoregion == 100 & ukcitizen == 1
**
ttest values_north == values_south if region5 == 2 & closetoregion == 100 & ukcitizen == 1
ttest geton_north == geton_south if region5 == 2 & closetoregion == 100 & ukcitizen == 1
ttest straight_north == straight_south if region5 == 2 & closetoregion == 100 & ukcitizen == 1

** Multivariate analysis of Northerners perceptions of southerners
logit values_south northerners2
logit values_south northerners2 age i.quals5 
logit values_south northerners2 age i.quals5 i.engbrit2
logit values_south northerners2 age i.quals5 i.engbrit2 auth_factor right_factor
*
logit geton_south northerners2
logit geton_south northerners2 age i.quals5 
logit geton_south northerners2 age i.quals5 i.engbrit2
logit geton_south northerners2 age i.quals5 i.engbrit2 auth_factor right_factor
*
logit straight_south northerners2
logit straight_south northerners2 age i.quals5 
logit straight_south northerners2 age i.quals5 i.engbrit2
logit straight_south northerners2 age i.quals5 i.engbrit2 auth_factor right_factor


****
** Analysis of missingness **
** STEP 1, generate a single variable for white British share my values = missing 
gen values_wb_all = values_awb
replace values_wb_all = values_bwb if values_wb_all == .
replace values_wb_all = values_cwb if values_wb_all == .
recode values_wb_all (0/1=0) (.=1) , gen (values_wb_missing)

recode w7_nidstrength_English (99=.), gen (idstrength_english)
logit values_wb_missing female age i.quals5 i.w7_polint i.region
logit values_wb_missing female age i.quals5 i.w7_polint i.region idstrength_english


***** FIGURE 1 ****
*****
mean values_south [pweight = finalweight], over (region) 
//mean geton_south [pweight = finalweight], over (region) 
//mean straight_south [pweight = finalweight], over (region) 
// Best items calcualted directly from Wave 8
use "Data\Wave 8.dta", clear
*******
recode w8_bestregionr1 (-99=.), gen (best_ne)
recode w8_bestregionr2 (-99=.), gen (best_nw)
recode w8_bestregionr3 (-99=.), gen (best_yh)
recode w8_bestregionr4 (-99=.), gen (best_em)
recode w8_bestregionr5 (-99=.), gen (best_wm)
recode w8_bestregionr6 (-99=.), gen (best_ee)
recode w8_bestregionr7 (-99=.), gen (best_lon)
recode w8_bestregionr8 (-99=.), gen (best_se)
recode w8_bestregionr9 (-99=.), gen (best_sw)
recode w8_bestregionr10 (-99=.), gen (best_w)
recode w8_bestregionr11 (-99=.), gen (best_s)
recode w8_bestregionr12 (-99=.), gen (best_ni)

mean best_ne [pweight = finalweight] if region == 1
mean best_nw [pweight = finalweight] if region == 2
mean best_yh [pweight = finalweight] if region == 3
mean best_em [pweight = finalweight] if region == 4
mean best_wm [pweight = finalweight] if region == 5
mean best_ee [pweight = finalweight] if region == 6
mean best_lon [pweight = finalweight] if region == 7
mean best_se [pweight = finalweight] if region == 8
mean best_sw [pweight = finalweight] if region == 9
mean best_w [pweight = finalweight] if region == 10
mean best_s [pweight = finalweight] if region == 11
mean best_ni [pweight = finalweight] if region == 12
